package com.bamboo.cmsservice.controller;


import com.bamboo.cmsservice.entity.CrmBanner;
import com.bamboo.cmsservice.entity.vo.BannerQuery;
import com.bamboo.cmsservice.service.CrmBannerService;
import com.bamboo.commonutils.ResponseEntity;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author jack.wu
 * @since 2020-07-12
 */
@Api(description = "轮播图管理")
@RestController
@RequestMapping("/cmsservice/banner/admin")
@CrossOrigin
public class BannerAdminController {

    @Resource
    private CrmBannerService bannerService;


    @ApiOperation(value = "带条件分页查询banner")
    @PostMapping("list/{current}/{limit}")
    public ResponseEntity pageBannerCondition(@PathVariable long current, @PathVariable long limit,
                                              @RequestBody(required = false) BannerQuery bannerQuery) {
        Page<CrmBanner> records = bannerService.pageBannerCondition(current, limit, bannerQuery);
        return ResponseEntity.ok().data("total", records.getTotal()).data("rows", records.getRecords());
    }


    @ApiOperation(value = "添加banner")
    @PostMapping("add")
    public ResponseEntity addBanner(@RequestBody CrmBanner banner) {
         bannerService.addBanner(banner);
        return ResponseEntity.ok();

    }

    @ApiOperation(value = "根据bannerId查询banner")
    @GetMapping("info/{id}")
    public ResponseEntity getBanner(@PathVariable String id) {
        CrmBanner banner = bannerService.getById(id);
        return ResponseEntity.ok().data("banner", banner);
    }

    @ApiOperation(value = "修改banner")
    @PutMapping("update")
    public ResponseEntity updateBanner(@RequestBody CrmBanner banner) {
        bannerService.updateBanner(banner);
        return ResponseEntity.ok();

    }

    @ApiOperation(value = "逻辑删除banner")
    @DeleteMapping("delete/{id}")
    public ResponseEntity removeBanner(@PathVariable String id) {
        bannerService.removeBanner(id);
        return ResponseEntity.ok();

    }
}

